
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

import { AboutSlint, Button } from "std-widgets.slint";


export global The_Global {
    in-out property <string> filename: "foo.txt";
}

component Issue9319 inherits Rectangle {
    callback activated(string);
    i9319 := ContextMenuArea {
        Menu {
            MenuItem {
                title: "Issue8319";
                activated => root.activated(self.title);
            }
        }
    }
}



export component TestCase inherits Window {
    in-out property <string> app_title: "Application";

    in property <bool> condition: true;

    width: 875px;
    height: 700px;
    HorizontalLayout {
        for model in 4 : Rectangle {
            ContextMenuArea {
                Menu {
                    MenuItem {
                        title: "Entry1";
                        activated => { debug("Entry1"); }
                    }
                    if true: Menu {
                        title: "Entry2";
                        MenuItem {
                            title: "New";
                            activated => { debug("New", model); }
                        }
                        MenuItem {
                            title: "Save " + The_Global.filename;
                        }
                        MenuSeparator {}
                        MenuItem {
                            title: "Exit " + app_title;
                            activated => {
                                app_title = "Exited " + model;
                            }
                        }
                        MenuItem {
                            property <physical-length> scale_factor: 25px;
                            title: "Sacle factor " + scale_factor/1phx;

                        }
                    }
                }
            }
        }
        if condition: Issue9319 {
            activated(title) => {
                app_title = title;
            }
        }
    }

    out property <bool> test: true;
}

/*
```rust
use slint::{platform::WindowEvent, platform::PointerEventButton, LogicalPosition, SharedString, platform::Key};
let instance = TestCase::new().unwrap();
assert!(instance.get_test());
// Right click to open the menu
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(400.0, 400.0), button: PointerEventButton::Right });
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(400.0, 400.0), button: PointerEventButton::Right });
// navigate to exit
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::UpArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::RightArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::Return));
assert_eq!(instance.get_app_title(), "Exited 2");

// Test for Issue8319
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(750.0, 100.0), button: PointerEventButton::Right });
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(751.0, 200.0), button: PointerEventButton::Right });
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::Return));
assert_eq!(instance.get_app_title(), "Issue8319");

```

```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
assert(instance.get_test());
// Right click to open the menu
instance.window().dispatch_pointer_press_event(slint::LogicalPosition({400.0, 400.0}), slint::PointerEventButton::Right);
instance.window().dispatch_pointer_release_event(slint::LogicalPosition({400.0, 400.0}), slint::PointerEventButton::Right);
// navigate to exit
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::UpArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::RightArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::Return);
assert_eq(instance.get_app_title(), "Exited 2");

// Test for Issue8319
instance.window().dispatch_pointer_press_event(slint::LogicalPosition({750.0, 100.0}), slint::PointerEventButton::Right);
instance.window().dispatch_pointer_release_event(slint::LogicalPosition({751.0, 200.0}), slint::PointerEventButton::Right);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::Return);
assert_eq(instance.get_app_title(), "Issue8319");

```
*/
